home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MOUSE.SWG / 0027_Easy Mouse Buttons.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  8KB  |  362 lines

  1. {
  2.  
  3.    This Unit is for Adding Buttons Easily to the screen, then checking to
  4.    See if they were hit or not...
  5.  
  6.  
  7.    Like so:
  8.  
  9.      CJ Cliife * Shareware Overload BBS (613)382-1924 & (613)382-8503
  10.                  Voice: (613)382-4194
  11. }
  12.  
  13. { THE MOUSER UNIT and a DEMO is at the end of this unit ... SST }
  14.  
  15. Unit BUTTUNIT;   (* 1995 CJ Cliffe *)
  16.  
  17. Interface
  18. Uses Mouser, Crt;
  19.  
  20. Var
  21.   butts : Array [1..1500] Of String [20];          { Up to 1500 Buttons }
  22.   buttx : Array [1..1500] Of ShortInt;             { Can Be used at the }
  23.   butty : Array [1..1500] Of ShortInt;             { Same time on screen}
  24.   buttx1: Array [1..1500] Of ShortInt;
  25.   butty1: Array [1..1500] Of ShortInt;
  26.  
  27.  
  28. Procedure Addbutt (butname1: String; X1, Y1, X2, Y2: Integer);{ Add a Button on
  29. the screen, at top left x1,y1, and bottom right x2,y2} {    Spots can be exact,
  30. because the numbers a trimmed to fit..        }
  31.  
  32.  
  33. Function  Checkbutt (butname2: String): Boolean;
  34. {  Simple, Check to see if a button is pressed! }
  35.  
  36.  
  37. Procedure InitButtons;
  38. {Used before each time a new screen of buttons is brought up}
  39.  
  40.  
  41. Procedure StopButtons;
  42. { Hides The mouse away from sight}
  43.  
  44. Function Leftpushed: Boolean;
  45. {Same as Leftpressed from MOUSE.PAS, but don't have to call up MOUSE.PAS}
  46.  
  47. Function Rightpushed: Boolean;
  48. {Same as Rightpressed from MOUSE.PAS, but don't have to call up MOUSE.PAS}
  49.  
  50.  
  51.  
  52. Implementation
  53.  
  54.  
  55. Procedure Addbutt (butname1: String; X1, Y1, X2, Y2: Integer);Var Cur: Integer;
  56. Begin
  57.   Cur := 0;
  58.   Repeat
  59.     Inc (cur);
  60.   Until (Cur = 1500) Or (butts [Cur] = ' ');
  61.   If Cur = 1500 Then
  62.   Begin
  63.     Write ('Button Limit Exceeded!', #7, #7, #7);
  64.     Delay (2000);
  65.     Halt;
  66.   End;
  67.   butts [cur] := Butname1;
  68.   buttx [cur] := X1 - 1;
  69.   butty [cur] := Y1 - 1;
  70.   buttx1 [cur] := X2 + 1;
  71.   butty1 [cur] := Y2 + 1;
  72. End;
  73.  
  74.  
  75.  
  76. Function Checkbutt (butname2: String): Boolean;   {Check to see if mouse is}
  77. Var                                               {   On top of a button   }
  78.   curx, cury: Integer;                            { If so, then Checkbutt  }
  79.   cou: Integer;                                   {         is True        } Begin
  80.   Cou := 0;
  81.   Checkbutt := False;
  82.   cury := getmousex;
  83.   curx := getmousey;
  84.   Inc (curx);                                   {Compensate to match Screen}
  85.   Inc (cury);
  86.   Repeat
  87.     Inc (cou);
  88.   Until (Cou = 1500) Or (butts [cou] = butname2);
  89.   If cou = 1500 Then                           {Button was not there at all}
  90.   Begin
  91.     Checkbutt := False;
  92.     Exit;
  93.   End;
  94.   If  (curx > butty [cou] )                      {Check to see if mouse is on}
  95.       And (cury > buttx [cou] )                  {        the button,        }
  96.       And (curx < butty1 [cou] )
  97.       And (cury < buttx1 [cou] )
  98.   Then Checkbutt := True;
  99. End;
  100.  
  101. Var setit: Integer;
  102.  
  103.  
  104. Procedure InitButtons;
  105. Begin
  106.   Resetmouse;
  107.   MouseWindow (0, 0, 79, 24);              { Keep Mouse Within Screen Limits }
  108.   For setit := 1 To 1500 Do
  109.   Begin
  110.     butts [setit] := ' ';                  {Reset All Buttons}
  111.     buttx [setit] := 0;
  112.     butty [setit] := 0;
  113.     buttx1 [setit] := 0;
  114.     butty1 [setit] := 0;
  115.   End;
  116.   Showmouse;
  117. End;
  118.  
  119.  
  120. Procedure StopButtons;
  121. Begin                              {Put the little Squeaker out of it's}
  122.   Hidemouse;                       {              Misery               } End;
  123.  
  124.  
  125. Function Leftpushed: Boolean;
  126. Begin
  127.   Leftpushed := False;
  128.   If Leftpressed Then Leftpushed := True;
  129. End;
  130.  
  131.  
  132. Function Rightpushed: Boolean;
  133. Begin
  134.   Rightpushed := False;
  135.   If Rightpressed Then Rightpushed := True;
  136. End;
  137.  
  138.  
  139.  
  140. Begin
  141.   If Not Mouseinstalled Then
  142.   Begin
  143.     TextColor (7);
  144.     TextBackground (0);
  145.     ClrScr;
  146.     WriteLn (' This program reqires a mouse, please install your mouse driver ');
  147.     WriteLn (' before running it... ');
  148.     Halt;
  149.   End;
  150. End.
  151.  
  152. { ---------------------------   MOUSER  UNIT  ------------------------ }
  153.  
  154. {This is some really GOOD stuff,  Bravo Bas! }
  155. Unit mouser;
  156. { Mouseunit for textmode. by Bas van Gaalen, Holland. }
  157. {      Slight Additions/Removals by CJ Cliffe         }
  158.  
  159. Interface
  160.  
  161. Const
  162.   mtypes : Array [0..4] Of String [6] = ('bus', 'serial', 'inport', 'ps/2', 'hp');
  163.   
  164. Var
  165.   buttons : Word;
  166.   verhi, verlo, mousetype : Byte;
  167.   driverinstalled : Boolean;
  168.   
  169. Function mouseinstalled : Boolean;
  170. Procedure resetmouse;
  171. Procedure getmouseversion;
  172. Procedure showmouse;
  173. Procedure hidemouse;
  174. Function getmousex : Byte;
  175. Function getmousey : Byte;
  176. Function leftpressed : Boolean;
  177. Function rightpressed : Boolean;
  178. Procedure mousewindow (X1, Y1, X2, Y2 : Byte);
  179.  
  180.  
  181. Implementation
  182.  
  183.  
  184. Function mouseinstalled : Boolean; Assembler; Asm
  185.   XOr AX, AX
  186.   Int 33h
  187.   cmp AX, - 1
  188.   je @skip
  189.   XOr AL, AL
  190.   @skip:
  191. End;
  192.  
  193. Procedure resetmouse; Assembler;
  194. Asm
  195.   XOr AX, AX
  196.   Int 33h
  197.   cmp AX, - 1
  198.   jne @skip
  199.   mov driverinstalled, True
  200.   mov buttons, BX
  201.   @skip:
  202. End;
  203.  
  204. Procedure getmouseversion; Assembler;
  205. Asm
  206.   mov AX, 24h
  207.   Int 33h
  208.   mov verhi, BH
  209.   mov verlo, BL
  210.   mov mousetype, CH
  211. End;
  212.  
  213. Procedure showmouse; Assembler;
  214. Asm
  215.   mov AX, 1
  216.   Int 33h
  217. End;
  218.  
  219. Procedure hidemouse; Assembler;
  220. Asm
  221.   mov AX, 2
  222.   Int 33h
  223. End;
  224.  
  225. Function getmousex : Byte; Assembler;
  226. Asm
  227.   mov AX, 3
  228.   Int 33h
  229.   ShR CX, 1
  230.   ShR CX, 1
  231.   ShR CX, 1
  232.   mov AX, CX
  233. End;
  234.  
  235. Function getmousey : Byte; Assembler;
  236. Asm
  237.   mov AX, 3
  238.   Int 33h
  239.   ShR DX, 1
  240.   ShR DX, 1
  241.   ShR DX, 1
  242.   mov AX, DX
  243. End;
  244.  
  245. Function leftpressed : Boolean; Assembler;
  246. Asm
  247.   mov AX, 3
  248.   Int 33h
  249.   And BX, 1
  250.   mov AX, BX
  251. End;
  252.  
  253. Function rightpressed : Boolean; Assembler;
  254. Asm
  255.   mov AX, 3
  256.   Int 33h
  257.   And BX, 2
  258.   mov AX, BX
  259. End;
  260.  
  261. Procedure mousewindow (X1, Y1, X2, Y2 : Byte); Assembler;
  262. Asm
  263.   mov AX, 7
  264.   XOr CH, CH
  265.   XOr DH, DH
  266.   mov CL, X1
  267.   ShL CX, 1
  268.   ShL CX, 1
  269.   ShL CX, 1
  270.   mov DL, X2
  271.   ShL DX, 1
  272.   ShL DX, 1
  273.   ShL DX, 1
  274.   Int 33h
  275.   mov AX, 8
  276.   XOr CH, CH
  277.   XOr DH, DH
  278.   mov CL, Y1
  279.   ShL CX, 1
  280.   ShL CX, 1
  281.   ShL CX, 1
  282.   mov DL, Y2
  283.   ShL DX, 1
  284.   ShL DX, 1
  285.   ShL DX, 1
  286.   Int 33h
  287. End;
  288.  
  289. End.
  290.  
  291.  
  292. { -----------------------   PROGRAM DEMO ---------------------------- }
  293.  
  294. Uses Crt, Buttunit;
  295.  
  296.  
  297. Var Finished: Boolean;
  298.  
  299. Procedure DrawButts;
  300. Begin
  301.   ClrScr;
  302.   Initbuttons;
  303.   Addbutt ('mybutt1', 20, 20, 28, 20);              {Easy Button Set-Up}
  304.   Addbutt ('mybutt2', 20, 21, 28, 21);
  305.   Addbutt ('mybutt3', 20, 22, 28, 22);
  306.   Addbutt ('quit',     1,  4,  8,  6);             {Buttons can be Any Size}
  307.   TextColor (15);
  308.   GotoXY (1, 1);
  309.   Write ('[ ]  #1   [ ] #2    [ ] #3    ');
  310.   GotoXY (20, 20);
  311.   TextBackground (1); TextColor (15);
  312.   Write (#221, 'Button1', #222);
  313.   GotoXY (20, 21);
  314.   TextBackground (2); TextColor (15);
  315.   Write (#221, 'Button2', #222);
  316.   GotoXY (20, 22);
  317.   TextBackground (3); TextColor (15);
  318.   Write (#221, 'Button3', #222);
  319.   TextBackground (1); TextColor (15);
  320.   GotoXY (1, 4);
  321.   WriteLn (#219, #223, #223, #223, #223, #223, #223, #219);
  322.   WriteLn (#221, ' Quit ', #222);
  323.   WriteLn (#219, #220, #220, #220, #220, #220, #220, #219);
  324.   TextBackground (0);
  325. End;
  326.  
  327.  
  328.  
  329. Procedure Checkbutts;
  330. Begin
  331.   If Checkbutt ('mybutt1') Then
  332.   Begin
  333.     GotoXY (2, 1);
  334.     TextColor (Random (8) + 8);
  335.     Write (#254);
  336.   End;
  337.   If Checkbutt ('mybutt2') Then
  338.   Begin
  339.     GotoXY (12, 1);
  340.     TextColor (Random (8) + 8);
  341.     Write (#254);
  342.   End;
  343.   If Checkbutt ('mybutt3') Then
  344.   Begin
  345.     GotoXY (22, 1);
  346.     TextColor (Random (8) + 8);
  347.     Write (#254);
  348.   End;
  349.   If Checkbutt ('quit') Then Finished := True;
  350.   Delay (200);
  351. End;
  352.  
  353.  
  354. Begin
  355.   Drawbutts;
  356.   Repeat
  357.     Repeat
  358.     Until LeftPushed;
  359.     Checkbutts;
  360.   Until Finished;
  361. End.
  362.